package com.thenie.chat.controller;


import com.thenie.chat.pojo.User;
import com.thenie.chat.service.IFriendService;
import com.thenie.chat.validator.CurrentUser;
import com.thenie.chat.vo.RespBean;
import com.thenie.chat.vo.RespBeanEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  好友关系 前端控制器
 * </p>
 *
 * @author thenie
 * @since 2022-05-22
 */
@RestController
@RequestMapping("/friend")
public class FriendController {

    @Autowired
    private IFriendService friendService;

    /**
     * 删除好友
     * @param user
     * @param friendId
     * @return
     */
    @PostMapping("/remove/{friendId}")
    public RespBean removeFriend(@CurrentUser User user, @PathVariable("friendId") Long friendId){
        if (user.getId().equals(friendId)){
            return RespBean.error(RespBeanEnum.UPDATE_USER_ERROR);
        }
        int ok = friendService.removeFriend(user.getId(), friendId);
        if (ok > 0){
            return RespBean.success(ok);
        }

        return RespBean.error(RespBeanEnum.NO_FRIEND_ERROR);
    }


}
